//按钮事件新增或编辑
var BD1D02_type = "";
//其他页面传到本页面参数
var BD1D02_param = {};
//暂时没用
var BD1D02_validate = "";
//当前触发按钮
var BD1D02_btn = "";

/*定义下拉框集合定义*/
/*declare select options begin*/
var BD1D02_ary_S_STATE = [{"MAIN_ID":"-1","CN_NAME":""},{"MAIN_ID":"1","CN_NAME":"启用"},{"MAIN_ID":"0","CN_NAME":"禁用"}];

/*declare select options end*/

//主从表传递参数
function BD1D02_param_set(){
	/*Main Subsuv Table Param Begin*/
	
	/*Main Subsuv Table Param end*/
}

//业务逻辑数据开始
function BD1D02_test_demo_biz_start(inputdata) {
	BD1D02_param = inputdata;
	layer.close(ly_index);
    /*biz begin*/
    $.each(BD1D02_ary_S_STATE, function (i, obj) {
        addOptionValue("BD1D02_S_STATE", obj[GetLowUpp("main_id")], s_decode(obj[GetLowUpp("cn_name")]));
    });
    BD1D02_init_test_demo()
	
    /*biz end*/
}

/*biz step begin*/
function BD1D02_format_S_STATE(value, row, index) {
    var objResult = value;
    for(i = 0; i < BD1D02_ary_S_STATE.length; i++) {
        var obj = BD1D02_ary_S_STATE[i];
        if (obj[GetLowUpp("main_id")].toString() == value.toString()) {
            objResult = s_decode(obj[GetLowUpp("cn_name")]);
            break;
        }
    }
    return objResult;
}


/*biz step end*/

/*查找框函数*/
/*find qry fun begin*/

function BD1D02_PIC_INFO_cn_name_fun(){
    BD1D02_btn = "PIC_INFO"
    index_subhtml = "t_sys_file2.vue";
    random_subhtml = "A088FR";
    if(loadHtmlSubVueFun("sys_vue/t_sys_file2.vue","BD1D02_test_demo_call_vue") == true){
        var n = Get_RandomDiv("A088FR","");
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                $('#A088FR_t_sys_file_Events').bootstrapTable('resetView');
                A088FR_param["ly_index"] = index;
                A088FR_param["target_name"] = "BD1D02_find_"+BD1D02_btn+"_cn_name";
                A088FR_param["target_id"] = "BD1D02_"+BD1D02_btn;
                A088FR_param["sourc_id"] = "MAIN_ID";
                A088FR_param["sourc_name"] = "NEW_FILE_NAME";
            },
            end: function(){
                $(n).hide();
            }
        });
     }
}

/*find qry fun end*/

/*页面结束*/
function BD1D02_page_end(){
	if(BD1D02_param["type"] == "edit"){
		BD1D02_get_edit_info();
	}
}

//页面初始化方法
function BD1D02_init_test_demo() {
	//type = getUrlParam("type");
	BD1D02_param_set();
	if(BD1D02_param["type"] == "add"){
//		$("#BD1D02_main_id").parent().parent().parent().hide();
		
		/*父页面查询条件参数传递至子页面并赋值*/
		/*Get Find Select param bgein*/
		if(BD1D02_param.hasOwnProperty("S_NAME"))
        	$("#BD1D02_S_NAME").val(BD1D02_param["S_NAME"]);
		if(BD1D02_param.hasOwnProperty("S_STATE"))
        	$("#BD1D02_S_STATE").val(BD1D02_param["S_STATE"]);
		
		/*Get Find Select param end*/	
	}
	else if(BD1D02_param["type"] == "edit"){
	
	}
	
	//表单验证
	BD1D02_checkFormInput();
	/*时间格式初始化*/
	/*form datetime init begin*/
	
    /*form datetime init end*/
	
	BD1D02_page_end();
}

//提交表单数据
function BD1D02_SubmitForm(){
	if(BD1D02_param["type"] == "add"){
		var inputdata = {
				"param_name": "N01_ins_test_demo",
				"session_id": session_id,
				"login_id": login_id
	            /*insert param begin*/
                ,"param_value1": s_encode($("#BD1D02_S_NAME").val())
                ,"param_value2": $("#BD1D02_S_STATE").val()
                ,"param_value3": s_encode($("#BD1D02_PIC_INFO").val())
                ,"param_value4": s_encode($("#BD1D02_S_FILE001").val())
				
	            /*insert param end*/
			};
		get_ajax_baseurl(inputdata, "BD1D02_get_N01_ins_test_demo");
	}
	else if(BD1D02_param["type"] == "edit"){
		var inputdata = {
				"param_name": "N01_upd_test_demo",
				"session_id": session_id,
				"login_id": login_id
	            /*update param begin*/
                ,"param_value1": s_encode($("#BD1D02_S_NAME").val())
                ,"param_value2": $("#BD1D02_S_STATE").val()
                ,"param_value3": s_encode($("#BD1D02_PIC_INFO").val())
                ,"param_value4": s_encode($("#BD1D02_S_FILE001").val())
                ,"param_value5": $("#BD1D02_MAIN_ID").val()
				
	            /*update param end*/
			};
		get_ajax_baseurl(inputdata, "BD1D02_get_N01_upd_test_demo");
	}
}

//vue回调
function BD1D02_test_demo_call_vue(objResult){
	if(index_subhtml == "XXXXXX")
	{
		
	}
	/*查询条件弹窗子页面*/
    /*get find subvue bgein*/
    else if(index_subhtml == "t_sys_file2.vue"){
        var n = Get_RandomDiv("A088FR",objResult);
        layer.open({
            type: 1,
            area: ['1100px', '600px'],
            fixed: false, //不固定
            maxmin: true,
            content: $(n),
            success: function(layero, index){
                var inputdata = {
                    "type":BD1D02_type,
                    "ly_index":index,
                    "target_name":"BD1D02_find_PIC_INFO_cn_name",
                    "target_id":"BD1D02_PIC_INFO",
                    "sourc_id":"MAIN_ID",
                    "sourc_name":"NEW_FILE_NAME"
                };
                loadScript_hasparam("sys_vue/t_sys_file2.js","A088FR_t_sys_file2_biz_start",inputdata);
            },
            end: function(){
                $(n).hide();
            }
        });
    }
	
	/*get find subvue end*/
}

//for表单提交
$("#BD1D02_save_test_demo_Edit").click(function () {
	$("form[name='BD1D02_DataModal']").submit();
})

/*修改数据*/
function BD1D02_get_N01_upd_test_demo(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_upd_test_demo) == true)
	{
		swal("修改数据成功!", "", "success");
		AD1D02_test_demo_query();
		BD1D02_clear_validate();
		layer.close(BD1D02_param["ly_index"]);
	}
}

/*添加数据*/
function BD1D02_get_N01_ins_test_demo(input) {
	layer.close(ly_index);
	if (Call_OpeResult(input.N01_ins_test_demo) == true)
	{
		swal("添加数据成功!", "", "success");
		AD1D02_test_demo_query();
		BD1D02_clear_validate();
		layer.close(BD1D02_param["ly_index"]);
	}
}

//取消编辑
$("#BD1D02_cancel_test_demo_Edit").click(function () {
	layer.close(BD1D02_param["ly_index"]);
	BD1D02_clear_validate();
	$("[id^='BD1D02_div']").hide();
})

//清除查找框
function BD1D02_clear_input_cn_name(obj1,obj2){
	$("#"+obj1).val("");
	$("#"+obj2).val("-1");
}

//清除验证缓存
function BD1D02_clear_validate(){
	$("#BD1D02_DataModal").find(".has-error").each(function(){
		$(this).removeClass('has-error');
	});
	$("#BD1D02_DataModal").find(".has-success").each(function(){
	 	$(this).removeClass('has-success');
	});
	$("#BD1D02_DataModal").find(".glyphicon").each(function(){
	 	$(this).remove();
	});
}

//输入框重置
function BD1D02_clear_edit_info(){
	var inputs = $("#BD1D02_DataModal").find('input');
	var selects = $("#BD1D02_DataModal").find("select");
	var textareas = $("#BD1D02_DataModal").find('textarea');
	$.each(inputs, function (i, obj) {
		$(obj).val("");
	});
	$.each(selects, function (i, obj) {
		$(obj).val("");
	});
	$.each(textareas, function (i, obj) {
		$(obj).val("");
	});
	/*清除输入框验证信息*/
	/*input validate clear begin*/
	
	/*input validate clear end*/
	BD1D02_init_test_demo();
}

//页面输入框赋值
function BD1D02_get_edit_info(){
	var rowData = $("#AD1D02_test_demo_Events").bootstrapTable('getData')[AD1D02_select_test_demo_rowId];
	var inputs = $("#BD1D02_DataModal").find('input');
	var selects = $("#BD1D02_DataModal").find("select");
	var textareas = $("#BD1D02_DataModal").find('textarea');
	
	//通用子页面输入框赋值
	Com_edit_info(rowData,inputs,selects,textareas,"AD1D02","BD1D02");
	
	/*文件附件格式*/
	/*input param fileinfo begin*/
	
	/*input param fileinfo end*/
}

//form验证
function BD1D02_checkFormInput() {
    BD1D02_validate = $("#BD1D02_DataModal").validate({
        errorElement: 'span',
        errorClass: 'help-block',
        rules: {
        	/*input check rules begin*/
            BD1D02_MAIN_ID: {}
            ,BD1D02_S_NAME: {maxlength:50}
            ,BD1D02_S_STATE: {}
            ,BD1D02_PIC_INFO: {maxlength:50}
            ,BD1D02_S_FILE001: {maxlength:50}
			
            /*input check rules end*/
        },
        messages: {
        	/*input check messages begin*/
            BD1D02_MAIN_ID: {}
            ,BD1D02_S_NAME: {maxlength:"长度不能超过50"}
            ,BD1D02_S_STATE: {}
            ,BD1D02_PIC_INFO: {maxlength:"长度不能超过50"}
            ,BD1D02_S_FILE001: {maxlength:"长度不能超过50"}
			
            /*input check messages end*/
        },
        errorPlacement: function (error, element) {
            element.next().remove();
            element.after('<span class="glyphicon glyphicon-remove form-control-feedback" aria-hidden="true"></span>');
            element.closest('.form-group').append(error);
        },
        highlight: function (element) {
            $(element).closest('.form-group').addClass('has-error has-feedback');
        },
        success: function (label) {
            var el = label.closest('.form-group').find("input");
            el.next().remove();
            el.after('<span class="glyphicon glyphicon-ok form-control-feedback" aria-hidden="true"></span>');
            label.closest('.form-group').removeClass('has-error').addClass("has-feedback has-success");
            label.remove();
        },
        submitHandler: function (form) {
        	BD1D02_SubmitForm();
        	return false;
        }
    })
}